#!/usr/bin/python3


from optparse import OptionParser
import sys
import os

sys.path.append("/usr/lib/linx-sec-center")
import ct_core

def create_parser():
    USAGE_MES="%prog \
            \n  Default: request no argument, you could input mac netlabel categories\
            \n          in stdin, and when you finished, Ctrl+D will be back and\
            \n          write the new categories to system if the The inputs correct!\
            \n Example:\
            \n secadmin~$ %prog \
            \n f1 f3 \
            \n EOF          "
    parse = OptionParser(usage=USAGE_MES,version="%prog 1.0")
    return parse

def set_cat_label():
    f = s = t = '-'
    line = sys.stdin.readline()
    l = line.split()
    if len(l) > 3 or len(l) == 0:
        print("You input %s is error!" %l)
        return
    f = l[0]
    if len(l) > 1:
        s = l[1]
    if len(l) > 2:
        t = l[2]
    if ct_core.check_net_cat(f,s,t):
        ct_core.write_mac_net_cat(f, s, t)


def main():
    parser = create_parser()
    args,flg = parser.parse_args()

    if not flg:
        print("Please input the new categories:")
        set_cat_label()
        return
    else:
        parser.error("Argument error, please specify a correct argument")

main()
